<template>
	<BaseContainer>
		<aplid-base-crud ref="crud" class="w-100" v-bind="options">
			<template v-slot:ArchivesDialog="{ row, show }">
				<Archives :api="baseConfig.api" :key="show" :nowRowData="row"></Archives>
			</template>
		</aplid-base-crud>
	</BaseContainer>
</template>

<script setup lang="ts">
import { baseConfig } from '@/views/datacenter/basicData/oldman/config'
import Archives from './Archives/index.vue'
import { getAreaObj } from '@/utils/util'

type Props = {
	query?: any
}
const props = withDefaults(defineProps<Props>(), {})

const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '户籍地区', prop: 'crAreaName' },
		{ label: '证件号码', prop: 'idCard', plusXing: '2,2' },
		{
			label: '姓名',
			prop: 'name',
		},
		{
			label: '性别',
			prop: 'genderLabel',
		},
		{ label: '年龄', prop: 'age' },
		{ label: '联系方式', prop: 'telephone', plusXing: '5,2' },
		{ label: '现居地区', prop: 'areas_name' },
		{
			label: '老人类别（政府兜底保障对象）',
			prop: 'elderlyType',
			custome: 'dict',
			code: 'ELDERLY_TYPE',
		},
		{ label: '入库时间', prop: 'createTime' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

const options = computed(() => {
	baseConfig.detailConfig.customeHeader.menuBtn = []
	return {
		...baseConfig,
    rowKey: 'recordUuid',
		api: {
			index: 'view_dpServiceObjectFile_page',
		},
		auth: {
			index: 'view_dpServiceObjectFile_page',
		},
		paramsObj: {
			...(props.query || {}),
		},
		menuBtn: [
			{
				icon: 'editor',
				label: '查看档案',
				type: 'primary',
				operate: 'Archives',
				auth: '',
				text: true,
				show: true,
			},
		],
		needPigeonhole: false,
		moreSearchConfig: undefined,
    tableConfig,
		beforeOnLoadFormate: async (params) => {
			let buildObj = {}
			if (params.buildInfo) {
				const buildName = params.buildInfoName?.split('/') || []
				buildObj = {
					checkinBuildingId: params.buildInfo[0],
					checkinFloor: params.buildInfo[1],
					checkinRoomId: params.buildInfo[2],
					checkinBedCodeId: params.buildInfo[3],

					checkinBuilding: buildName[0],
					checkinRoom: buildName[2],
					checkinBedCode: buildName[3],
				}
			}
			const areasObj: any = getAreaObj(params.areas, '')
			const crAreasObj: any = getAreaObj(params.crAreas, 'cr')

			return Promise.resolve({
				...params,
				...buildObj,
				...areasObj,
				...crAreasObj,
        crAddress: undefined,
			  address: undefined,
				areas: undefined,
				crAreas: undefined,
				buildInfo: undefined,
				buildInfoName: undefined,
			})
		},
	}
})
</script>

<style lang="scss" scoped></style>
